package com.nektos.ccf.client;

import java.util.List;

import org.apache.tools.ant.taskdefs.Available;

import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.adapters.SimpleEditor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.ValueBoxBase.TextAlignment;
import com.nektos.ccf.shared.Committee;
import com.nektos.ccf.shared.CommitteeList;
import com.nektos.ccf.shared.Volunteer;
import com.google.gwt.user.client.ui.ListBox;

public class VolunteerForm extends AbsolutePanel implements Editor<Volunteer>{
    private SubmitHandler submitHandler;
    
    TextBox fullName;
    TextBox address;
    TextBox phone;
    TextBox cell;
    TextBox email;
    IntegerBox survivorYears;
    TextBox datesUnavailable;
    TextArea priorVolunteerWork;
    CheckBox willingToLead;
    TextArea about;
    
    RadioButton willingToModel;
    RadioButton onlyAvailableDayOfEvent;
    CheckBoxList interests = new CheckBoxList();

	private ListBox shirtSize;

    public VolunteerForm() {
    	setSize("700px", "953px");
        initWidget();
	}
    
    public void setSubmitHandler(SubmitHandler submitHandler) {
    	this.submitHandler = submitHandler;
    }
    
    public Editor<String> shirtSize() {
    	return SimpleEditor.of(shirtSize.getItemText(shirtSize.getSelectedIndex()));
    }
    
	private void initWidget() {
        FlexTable flexTable = new FlexTable();
        flexTable.setStyleName("section");
        this.add(flexTable, 10, 102);
        flexTable.setSize("312px", "204px");
        
        Label nlnlblFullName = new Label("Full Name");
        flexTable.setWidget(0, 0, nlnlblFullName);
        
        fullName = new TextBox();
        flexTable.setWidget(0, 1, fullName);
        fullName.setName("fullName");
        fullName.setMaxLength(40);
        flexTable.getCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE);
        flexTable.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        flexTable.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
        
        Label nlnlblAddress = new Label("Address");
        flexTable.setWidget(1, 0, nlnlblAddress);
        
        address = new TextBox();
        address.setName("address");
        flexTable.setWidget(1, 1, address);
        flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        
        Label nlnlblPhone = new Label("Phone");
        flexTable.setWidget(2, 0, nlnlblPhone);
        flexTable.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        
        phone = new TextBox();
        phone.setName("phone");
        flexTable.setWidget(2, 1, phone);
        
        Label lblCell = new Label("Cell #");
        flexTable.setWidget(3, 0, lblCell);
        flexTable.getCellFormatter().setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        
        cell = new TextBox();
        cell.setName("cell");
        flexTable.setWidget(3, 1, cell);
        flexTable.getCellFormatter().setHorizontalAlignment(3, 1, HasHorizontalAlignment.ALIGN_LEFT);
        
        Label lblNewLabel = new Label("Email Address");
        flexTable.setWidget(4, 0, lblNewLabel);
        
        email = new TextBox();
        email.setName("email");
        flexTable.setWidget(4, 1, email);
        flexTable.getCellFormatter().setHorizontalAlignment(4, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        
        Label lblNewLabel_2 = new Label("Shirt Size");
        flexTable.setWidget(5, 0, lblNewLabel_2);
        flexTable.getCellFormatter().setHorizontalAlignment(5, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        
        shirtSize = new ListBox();
        shirtSize.addItem("Small");
        shirtSize.addItem("Medium");
        shirtSize.addItem("Large");
        shirtSize.addItem("X-Large");
        shirtSize.addItem("XX-Large");
        shirtSize.addItem("XXX-Large");
        shirtSize.setSelectedIndex(2);
        shirtSize.setVisibleItemCount(1);
        flexTable.setWidget(5, 1, shirtSize);
        flexTable.getCellFormatter().setWidth(5, 1, "");
        
        FlexTable flexTable_2 = new FlexTable();
        flexTable_2.setStyleName("section");
        this.add(flexTable_2, 338, 102);
        flexTable_2.setSize("348px", "180px");
        
        Label lblNewLabel_1 = new Label("Availability");
        flexTable_2.setWidget(0, 0, lblNewLabel_1);
        lblNewLabel_1.setWidth("341px");
        
        VerticalPanel verticalPanel = new VerticalPanel();
        flexTable_2.setWidget(1, 0, verticalPanel);
        verticalPanel.setSize("310px", "125px");
        
        
        
        onlyAvailableDayOfEvent = new RadioButton("availability", "I am interested in volunteering only the day or week of the event");
        onlyAvailableDayOfEvent.setValue(true);
        verticalPanel.add(onlyAvailableDayOfEvent);
        onlyAvailableDayOfEvent.setWidth("304px");
        verticalPanel.setCellVerticalAlignment(onlyAvailableDayOfEvent, HasVerticalAlignment.ALIGN_MIDDLE);
        verticalPanel.setCellHeight(onlyAvailableDayOfEvent, "50");
        
        RadioButton dayOfOnly_NO = new RadioButton("availability", "I will volunteer throughout the year; I will be unavailable on these dates");
        dayOfOnly_NO.setValue(false);
        verticalPanel.add(dayOfOnly_NO);
        dayOfOnly_NO.setSize("302px", "42px");
        
        datesUnavailable = new TextBox();
        verticalPanel.add(datesUnavailable);
        datesUnavailable.setWidth("269px");
        
        VerticalPanel verticalPanel_1 = new VerticalPanel();
        verticalPanel_1.setStyleName("section");
        this.add(verticalPanel_1, 338, 312);
        verticalPanel_1.setSize("349px", "116px");
        
        Label lblHaveVolunteeredBefore = new Label("If you volunteered before, what did you do?");
        verticalPanel_1.add(lblHaveVolunteeredBefore);
        lblHaveVolunteeredBefore.setWordWrap(false);
        lblHaveVolunteeredBefore.setWidth("103px");
        
        priorVolunteerWork = new TextArea();
        verticalPanel_1.add(priorVolunteerWork);
        verticalPanel_1.setCellHorizontalAlignment(priorVolunteerWork, HasHorizontalAlignment.ALIGN_CENTER);
        priorVolunteerWork.setSize("328px", "64px");
        
        willingToLead = new CheckBox("I'm interested in taking a leadership role this time");
        verticalPanel_1.add(willingToLead);
        
        FlexTable flexTable_3 = new FlexTable();
        flexTable_3.setStyleName("section");
        this.add(flexTable_3, 10, 336);
        flexTable_3.setSize("310px", "94px");
        
        Label lblIfYouAre = new Label("If you are a breast cancer survivor, how many years?");
        flexTable_3.setWidget(0, 0, lblIfYouAre);
        
        survivorYears = new IntegerBox();
        flexTable_3.setWidget(0, 1, survivorYears);
        survivorYears.setWidth("54px");
        
        Label lblAreYouWilling = new Label("Are you willing to model?");
        flexTable_3.setWidget(1, 0, lblAreYouWilling);
        
        VerticalPanel verticalPanel_2 = new VerticalPanel();
        flexTable_3.setWidget(1, 1, verticalPanel_2);
        
        willingToModel = new RadioButton("model", "Yes");
        verticalPanel_2.add(willingToModel);
        
        RadioButton willingToModel_NO = new RadioButton("model", "No");
        willingToModel_NO.setValue(true);
        verticalPanel_2.add(willingToModel_NO);
        
        
        PushButton pshbtnNewButton = new PushButton("Register!");
        pshbtnNewButton.setHTML("Register!");
        pshbtnNewButton.addClickHandler(new ClickHandler() {
        	public void onClick(ClickEvent event) {
                try {
                    submitHandler.handleSubmit();
                } catch (Exception ex) {
                	ex.printStackTrace();
                }

        	}
        });
        this.add(pshbtnNewButton, 185, 876);
        pshbtnNewButton.setSize("110px", "29px");
        
        PushButton pushButton = new PushButton("Cancel");
        pushButton.setHTML("Cancel");
        pushButton.addClickHandler(new ClickHandler() {
        	public void onClick(ClickEvent event) {
                Window.open("/", "_self", null);
        	}
        });
        this.add(pushButton, 349, 876);
        pushButton.setSize("77px", "29px");
        
        VerticalPanel verticalPanel_3 = new VerticalPanel();
        verticalPanel_3.setStyleName("section");
        this.add(verticalPanel_3, 10, 697);
        verticalPanel_3.setSize("678px", "159px");
        
        Label lblPleaseTellUs = new Label("Please tell us about you (Strengths, skills, interests)");
        verticalPanel_3.add(lblPleaseTellUs);
        lblPleaseTellUs.setWidth("652px");
        verticalPanel_3.setCellHorizontalAlignment(lblPleaseTellUs, HasHorizontalAlignment.ALIGN_CENTER);
        
        about = new TextArea();
        verticalPanel_3.add(about);
        verticalPanel_3.setCellHorizontalAlignment(about, HasHorizontalAlignment.ALIGN_CENTER);
        about.setSize("643px", "102px");
        
        VerticalPanel verticalPanel_4 = new VerticalPanel();
        verticalPanel_4.setStyleName("section");
        this.add(verticalPanel_4, 10, 436);
        verticalPanel_4.setSize("678px", "217px");
        
        Label lblPleaseSelectAny = new Label("Please select any areas in which you might be interested:");
        verticalPanel_4.add(lblPleaseSelectAny);
        verticalPanel_4.setCellHorizontalAlignment(lblPleaseSelectAny, HasHorizontalAlignment.ALIGN_CENTER);
        lblPleaseSelectAny.setWidth("674px");
        
        CommitteeList coms = CommitteeList.get();
        int rows = (coms.size()/4) + 1;
        Grid grid = new Grid(rows, 4);
        verticalPanel_4.add(grid);
        grid.setSize("674px", "181px");
        
        int r = 0;
        int c = 0;
        for(Committee com: coms) {
            grid.setWidget(r,c++, interests.add(com.getName(),com.getDescription()));
            if(c==4){
            	r++;
            	c=0;
            }
        }
        
        DecoratorPanel decoratorPanel = new DecoratorPanel();
        this.add(decoratorPanel, 10, 10);
        decoratorPanel.setSize("677px", "88px");
        
        HorizontalPanel horizontalPanel = new HorizontalPanel();
        horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        horizontalPanel.setStyleName("header");
        decoratorPanel.setWidget(horizontalPanel);
        horizontalPanel.setSize("670px", "71px");
        
        Image image = new Image("logo_sm.png");
        horizontalPanel.add(image);
        image.setSize("201px", "71px");
        
        Label lblCelebration = new Label("Volunteer Registration");
        horizontalPanel.add(lblCelebration);
        lblCelebration.setStyleName("header");
        lblCelebration.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        lblCelebration.setSize("453px", "61px");
		
	}
    
	
}
